﻿Ext.define('app.system.rdcenter.Edit',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    modal: true,
    //maximized: true,
    width: 600,
    height: 400,
    layout: 'fit',
    rdCenterId: 0,
    businessId: 0,
    bodyStyle: 'padding:30px',
    initComponent: function () {
        var me = this;
        me.items = [me.getForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSubmit },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    listeners: {
        afterrender: function (win) {
            if (win.rdCenterId > 0) {
                App.AjaxGet('/api/services/app/rdCenter/Get?rdCenterId=' + win.rdCenterId, function (data) {
                    win.form.getForm().setValues(data.result);
                });
            }
        }
    },
    getForm: function () {
        var me = this;
        if (!this.form) {
            this.form = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        hidden: true,
                        name: 'id',
                        value: 0
                    },
                    {
                        fieldLabel: '名称',
                        allowBlank: false,
                        name: 'name'
                    },
                    {
                        fieldLabel: '负责人',
                        allowBlank: false,
                        name: 'principal'
                    },
                    {
                        xtype: 'hidden',
                        name: 'businessId',
                        value: me.businessId
                        //fieldLabel: '事业部',
                        //editable:false,
                        //store: Ext.create("app.ux.PrmStore", { url: '/api/services/app/business/GetAll' }),
                        //queryMode: 'local',
                        //displayField: 'name',
                        //valueField: 'id',
                    }
                ]
            });
        }
        return this.form;
    },
    onSubmit: function () {
        var me = this;
        var json = me.getForm().getForm().getValues();
        App.AjaxPost('/api/services/app/rdCenter/CreateOrEdit', json, function () {
            me.fireEvent("savesuccess");
        });
    }
});